// app_zwpro/pages/datail/datail.js
var app = getApp();
var videoAd = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datails: '',
    appstore_name: '',
    ad_game: null,
    password: '',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;
    console.log(id)
    var t = this;
    app.util.request({
      'url': "entry/wxapp/datails",
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        id: id,
      },
      success(a) {
        console.log(a)
        t.setData({
          datails: a.data.data.data,
          url: a.data.data.url,
          password: a.data.data.data.password,
          
        })
      }
    });
    app.util.request({
      'url': "entry/wxapp/config",
      success(a) {
        console.log(a)
        t.setData({
          appstore_name: a.data.data.data[0].appstore_name,
          ad_game: a.data.data.data[0].ad_game,
        })
      }
    });
  },
  
  showModal: function (e) {
    console.log(e);
    var t = this;
    t.setData({
      modalName: e.currentTarget.dataset.target
    });
  },

  hideModal: function (e) {
    var t = this;
    t.setData({
      modalName: null
    });
  },

  copyLink: function (e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.link,
      success: res => {
        wx.showToast({
          title: '地址复制成功',
          icon: "success",
          duration: 2000,
        })
      }
    });
  },

  copyAccount: function (e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.account,
      success: res => {
        wx.showToast({
          title: '地址复制成功',
          icon: "success",
          duration: 2000,
        })
      }
    });
  },

  adShwo: function (t) {
    console.log(t);
    var a = t.currentTarget.dataset.type,
      i = this,
      e = wx.createRewardedVideoAd({
        adUnitId: i.data.ad_game
      });
    e.offLoad(), e.offClose(), e.offError(), e.load().then(function () {
      return e.show();
    }).catch(function (t) {
      return console.log("cuowu", t.errMsg);
    }), e.onError(function (t) {
      console.log("错误", t), (console.log("复制密码"),
        i.copyPassword());
    }), e.onClose(function (e) {
      if (e && e.isEnded || void 0 === e) console.log("看完了！"), (console.log("复制密码"),
        i.copyPassword());
      else {
        console.log("没看完！");
        var n = "";
        n = "看完广告后自动复制密码!",
          wx.showModal({
            title: "温馨提示：",
            content: n,
            showCancel: !0,
            cancelText: "取消",
            cancelColor: "#00baff",
            confirmText: "确定",
            confirmColor: "#00baff",
            success: function (e) {
              e.cancel || (t.currentTarget.dataset.type = a, i.adShwo(t));
            }
          });
      }
    });
  },

  copyPassword: function () {
    var t = this;
    wx.setClipboardData({
      data: t.data.password,
      success: function (t) {
        wx.showToast({
          title: "密码复制成功",
          icon: "success",
          duration: 2000
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})